package com.common;

import com.desgin.enums.ModelEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author zhaofang
 * @version 1.0
 * @since 2021/8/13 14:09
 **/
@Data
public class ResponseVO<T> implements Serializable {

    private static final long serialVersionUID = 680741136094280332L;

    private String code;

    private String message;

    private T data;

    public ResponseVO() {
        this.code = ModelEnum.respCode.OK.getCode();
        this.message = ModelEnum.respCode.OK.getMsg();
        this.data = null;
    }

    public ResponseVO(T data) {
        this.code = ModelEnum.respCode.OK.getCode();
        this.message = ModelEnum.respCode.OK.getMsg();
        this.data = data;
    }

    public ResponseVO(String code,String message,T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseVO<T> build(ModelEnum error) {
        return new ResponseVO(ModelEnum.respCode.ERROR.getCode(), ModelEnum.respCode.ERROR.getMsg(), null);
    }

    public static <T> ResponseVO<T> build(ModelEnum error, T data) {
        return new ResponseVO(ModelEnum.respCode.ERROR.getCode(), ModelEnum.respCode.ERROR.getMsg(), data);
    }

    public static <T> ResponseVO<T> build(String code, String message, T data) {
        return new ResponseVO<>(code, message, data);
    }

    public static <T> ResponseVO<T> ok(T data) {
        return new ResponseVO(data);
    }
}